package com.okaysoft.ofb.account

class Role {

    static List<Map> DEFAULT_ROLE = [[name:'匿名用户',authority:'IS_AUTHENTICATED_ANONYMOUSLY'],[name:'登录用户',authority:'IS_AUTHENTICATED_FULLY']]
    String name
	String authority

	static mapping = {
		cache true
	}

	static constraints = {
        name nullable: true
		authority blank: false, unique: true
	}

    /**
     * 获取当前角色拥有的菜单模块.
     *
     * @return
     */
    List<Requestmap> getRequestmaps(){
        return Requestmap.findAllByConfigAttributeLikeAndMenuEnabled("%"+this.authority+"%",Boolean.TRUE)
    }

    /**
     * 获取当前角色拥有的所有模块.
     *
     * @return
     */
    List<Requestmap> getAllRequestmaps(){
        return Requestmap.findAllByConfigAttributeLike("%"+this.authority+"%")
    }
}
